<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <link rel="stylesheet" href="layui/css/layui.css"/>
    <script type="text/javascript" src="layui/layui.js"></script>
    <script type="text/javascript" src="layui/tableSelect.js"></script>

</head>
<body>
<script type="text/html" id="toolbarDemo">
    <button class="layui-btn layui-btn-sm" lay-event="insert" id="addUser"><i
            class="layui-icon">&#xe654;</i>新增
    </button>
    <button class="layui-btn layui-btn-sm" lay-event="deleteAll">批量删除</button>
    <div class="layui-inline" style="float:right;height:29px;" title="搜索" lay-event="search"><i
            class="layui-icon layui-icon-search"></i></div>
    <input type="text" id="fundsAllotId"  style="width:200px;float:right;height:30px;" placeholder="请输入日期时间" autocomplete="off" class="layui-input">
</script>
<script type="text/html" id="FundsAllot">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<table class="layui-hide" id="myTable" lay-filter="myTable" ></table>
<script>
    layui.use(['table', 'form', 'tableSelect','laydate'],  function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;
        var laydate = layui.laydate;
        tableSelect = layui.tableSelect;

        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        //详见：/docs/modules/table.html#totalRow
        table.render({
            height: 'full-55'
            , minLength: 80,
             elem: '#myTable'
            ,id:'myTable'
            , url: 'securityAccruedSelect'
            , toolbar: '#toolbarDemo'
            , title: '资金调拨表'
            , page: true
            , limits:[2,4,6,8]
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'securityAccruedId', title: '证券应收应付ID',align:'center'}
                ,{field: 'businessTime', title: '业务日期',align:'center'}
                ,{field: 'fundId', title: '基金ID',align:'center',hide:true}
                ,{field: 'cashId', title: '银行账户编号',align:'center'}
                ,{field: 'securityId', title: '证券编号',align:'center'}
                ,{field: 'securityName', title: '证券名称',align:'center'}
                ,{field: 'businessType',align:'center', title: '业务类型', templet: function (item) {
                        if (item.businessType=='1'){
                            return '为清算款';
                        }else if (item.businessType=='2'){
                            return '估值增值'
                        }else if (item.businessType=='3'){
                            return '债券利息'
                        }
                    }}
                ,{field: 'fundFlow',align:'center', title: '资金流向',templet:function (item) {
                        if (item.fundFlow=='1'){
                            return '流入';
                        }else if (item.fundFlow=='2'){
                            return '流出';
                        }
                    }}
                ,{field: 'money', title: '金额',align:'center'}
                , {fixed: 'right', title: '操作', toolbar: '#FundsAllot',align:'center'}
            ]]
        });

        laydate.render({
            elem:'#fundsAllotId'
        })

        //工具栏事件
        table.on('toolbar(myTable)',  function  (obj) {
            if (obj.event == 'insert') {
                //点击按钮的时候，弹出一个添加页面
                layer.open({
                    type: 1,
                    title: '添加基金信息',
                    closeBtn: 1,
                    move:false,
                    area: ['800px', '400px'],
                    content:$("#addContent")
                });
            }else if (obj.event == 'search'){
                var fundsAllotId=$("#fundsAllotId").val();
                alert(fundsAllotId);
                table.reload('myTable', {
                    method: 'post',
                    page: {
                        curr : 1
                    },
                    where: {
                        'businessTime': fundsAllotId
                    },
                });
                laydate.render({
                    elem:'#fundsAllotId'
                })
                $("#fundsAllotId").val(fundsAllotId);
            }

        });

        //给最右边的列 添加事件
        table.on('tool(myTable)',function (obj) {
            switch (obj.event) {
                case "edit":
                    //得到选中行的数据
                    var data=obj.data;
                    //JSON.stringify(data)  拼接成JSON格式的字符串
                    var bookObj=$.parseJSON(JSON.stringify(data));
                    //弹出一个修改的窗口
                    form.val("editform",bookObj);
                    layer.open({
                        type:1, //iframe 内嵌窗口
                        title: '修改基金设置信息',
                        area: ['800px', '400px'],
                        content: $("#editContent")
                    });
                    break;
                case "del":
                    // alert("这是删除的操作");
                    alert("选中的行：" + obj.data.securityAccruedId);
                    layer.confirm('您确定要删除吗', function (index) {
                        console.log(obj.data.securityAccruedId)
                        $.getJSON("securityAccruedDelete"
                            , {securityAccruedId: obj.data.securityAccruedId}
                            , function (msg) {
                                if (msg == 1) {
                                    layer.close(index)
                                    table.reload('myTable');
                                }
                            })
                    })
                    break;
            }
        });
        //给增加的form绑定提交事件
        form.on('submit(addsubmit)',function () {
            alert("新增表单提交");
            //发送ajax请求到 服务器，
            //得到表单的所有数据
            var formData= form.val("addform");
            // alert('formData=' + formData);
            $.post(
                "securityAccruedInsert",
                formData,
                function(msg) {
                    //重新刷新表格
                    //给予提示信息，增加成功
                    // alert(msg);
                    if(msg==0){
                        alert('增加失败');
                    }else {
                        alert('增加成功')
                    }
                });
        });
        //给修改的form绑定提交事件
        form.on('submit(editform)',function () {
            //发送ajax请求到 服务器，
            //得到表单的所有数据
            var formData= form.val("editform");
            // alert('formData=' + formData);
            $.post(
                "securityAccruedUpdate",
                formData,
                function(msg) {
                    //重新刷新表格
                    //给予提示信息，修改成功
                    // alert(msg);
                    if(msg==0){
                        alert('修改失败');
                    }else {
                        alert('修改成功');
                    }
                });

        });

        laydate.render({
            elem:'#businessTime'
        })


        //新增托管人下拉表格
        tableSelect.render({
            elem: '#securityId',
            checkedKey: 'securityId',
            table: {
                url: 'selectSecurity',
                cols: [
                    [
                        {type: 'radio', fixed: 'left'},
                        ,{field: 'securityId', title: 'ID', fixed: 'left'}
                        ,{field: 'securityName', title: '证券名称'}
                        ,{field: 'releaseDate', title: '发行日期'}
                    ]]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.securityId)
                    $("#securityIdHidden").val(item.securityId)
                });
                elem.val(NEWJSON.join(","))
            }
        });

        tableSelect.render({
            elem: '#SecuId',
            checkedKey: 'securityId',
            table: {
                url: 'selectSecurity',
                cols: [
                    [
                        {type: 'radio', fixed: 'left'},
                        ,{field: 'securityId', title: 'ID', fixed: 'left'}
                        ,{field: 'securityName', title: '证券名称'}
                        ,{field: 'releaseDate', title: '发行日期'}
                    ]]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.securityId)
                    $("#SecuIdHidden").val(item.securityId)
                });
                elem.val(NEWJSON.join(","))
            }
        });

        tableSelect.render({
            elem: '#cashId',
            checkedKey: 'cashId',
            table: {
                url: 'selectCash',
                cols: [
                    [
                        {type: 'radio', fixed: 'left'},
                        , {field: 'cashId', title: '现金账号ID',edit: 'text', fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                        , {field: 'bankId', title: '银行卡号', edit: 'text'}
                        , {field: 'accountName', title: '账户名称', edit: 'text'}
                        , {field: 'bankName', title: '银行名称', edit: 'text'}
                    ]]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.cashId)
                    $("#hiddenFundName").val(item.cashId)
                });
                elem.val(NEWJSON.join(","))
            }
        });
        tableSelect.render({
            elem: '#CShId',
            checkedKey: 'cashId',
            table: {
                url: 'selectCash',
                cols: [
                    [
                        {type: 'radio', fixed: 'left'},
                        , {field: 'cashId', title: '现金账号ID',edit: 'text', fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                        , {field: 'bankId', title: '银行卡号', edit: 'text'}
                        , {field: 'accountName', title: '账户名称', edit: 'text'}
                        , {field: 'bankName', title: '银行名称', edit: 'text'}
                    ]]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.cashId)
                    $("#fundName").val(item.cashId)
                });
                elem.val(NEWJSON.join(","))
            }
        });
    });
</script>

<!--增加的div内容-->
<div id="addContent"
     style="display: none; height: 100%; height: 100%; text-align: center;">
    <form id="addform" lay-filter="addform"
          class="layui-form layui-form-pane"
          style="margin: 30px auto; display: inline-block;">
        <div class="layui-form-item" style="atext-align: center;">
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 35px;">业务日期</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="businessTime" id="businessTime"
                       autocomplete="off" placeholder="请输入业务日期" class="layui-input">
            </div>
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 50px;">银行账户编号</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="cashId" id="cashId"
                       autocomplete="off" placeholder="请输入银行账户编号" class="layui-input">
                <input type="hidden" name="fundName" id="hiddenFundName">
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 35px">证券编号</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required"
                       autocomplete="off" placeholder="请输入证券编号" class="layui-input" name="securityId" id="securityId">
                <input type="hidden" name="securityIdHidden" id="securityIdHidden">
            </div>
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 50px;">业务类型</label>
            <div class="layui-input-inline">
                <select name="businessType" >
                    <option placeholder="请选择"></option>
                    <option value="1" >清算款</option>
                    <option value="2">估值增值</option>
                    <option value="3">债券利息</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 35px">资金流向</label>
            <div class="layui-input-inline">
                <select name="fundFlow" >
                    <option placeholder="请选择"></option>
                    <option value="1">流入</option>
                    <option value="2">流出</option>
                </select>
            </div>
            <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 50px">金额</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required"
                       autocomplete="off" placeholder="请输入金额" class="layui-input" name="money">
            </div>
        </div>
        <div class="layui-form-item" style="position: absolute;left: 28%; bottom: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="addsubmit"><i class="layui-icon">&#x1005;</i>添加</button>
                <button type="reset" class="layui-btn layui-btn-primary"> <i class="layui-icon">&#x1006;</i>取消</button>
            </div>
        </div>
    </form>
</div>
<!--修改的div内容-->
<div id="editContent"
     style="display: none; height: 100%; height: 100%; text-align: center;">
    <form id="editform" lay-filter="editform"
          class="layui-form layui-form-pane"
          style="margin: 30px auto; display: inline-block;">
        <div class="layui-form-item" style="text-align: center;">
            <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 35px">证券应收应付ID</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required"
                       autocomplete="off" placeholder="请输入证券应收应付ID" class="layui-input" name="securityAccruedId">
            </div>
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 50px;">业务日期</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="businessTime" id="BITime"
                       autocomplete="off" placeholder="请输入业务日期" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="atext-align: center;">
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 35px;">基金ID</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="fundId"
                       autocomplete="off" placeholder="请输入基金ID" class="layui-input">
            </div>
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 50px;">银行账户编号</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="cashId" id="CShId"
                       autocomplete="off" placeholder="请输入银行账户编号" class="layui-input">
                <input type="hidden" name="fundName" id="FundName">
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 35px">证券编号</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required"
                       autocomplete="off" placeholder="请输入证券编号" class="layui-input" name="securityId" id="SecuId">
                <input type="hidden" name="securityIdHidden" id="SecuIdHidden">
            </div>
            <label class="layui-form-label layui-bg-gray" style=" width: 140px;margin-left: 50px;">业务类型</label>
            <div class="layui-input-inline">
                <select name="businessType" >
                    <option placeholder="请选择"></option>
                    <option value="1" >清算款</option>
                    <option value="2">估值增值</option>
                    <option value="3">债券利息</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 35px">资金流向</label>
            <div class="layui-input-inline">
                <select name="fundFlow" >
                    <option placeholder="请选择"></option>
                    <option value="1">流入</option>
                    <option value="2">流出</option>
                </select>
            </div>
            <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 50px">金额</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required"
                       autocomplete="off" placeholder="请输入金额" class="layui-input" name="money">
            </div>
        </div>
        <div class="layui-form-item" style="position: absolute;left: 28%; bottom: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="addsubmit"><i class="layui-icon">&#x1005;</i>添加</button>
                <button type="reset" class="layui-btn layui-btn-primary"> <i class="layui-icon">&#x1006;</i>取消</button>
            </div>
        </div>
    </form>
</div>
</body>
</html>